package org.smart.framework.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @Auther Uncle_Z
 * @date 2017/8/30 22:26
 * @Email:2545375@qq.com
 * @Descrition 流操作工具类
 * @since 1.0
 */

public final class StreamUtil {

    private static final Logger LOGGER = LogManager.getLogger(StreamUtil.class);

    public static String getString(InputStream is) {
        StringBuilder sb = new StringBuilder();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line;
            if ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        } catch (Exception e) {
            LOGGER.error("get String failure",e);
            throw new RuntimeException(e);
        }

        return sb.toString();
    }
}
